package cn.yinzhiping.redislearn.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author yinzhiping
 */
@Service
public class TranTestController {
    @Autowired
    StringRedisTemplate redisTemplate;

    @Transactional(rollbackFor = Exception.class)
    public void test(){
        this.insert();
        //模拟出现故障
        //redisTemplate=null;
        this.update();
    }

    public void insert(){
        redisTemplate.opsForValue().set("test-transactaional","1234");
    }

    public void update(){
        redisTemplate.opsForValue().set("zdy-transactaional","1234789-");
    }
}
